package net.qiqb.lock;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;


@Slf4j
public class DefaultTopicLock implements TopicLock {

    protected String name;

    private final Lock workLock;

    public DefaultTopicLock(String name, Lock lock) {
        this.name = name;
        this.workLock = lock;
    }

    @Override
    public String getName() {
        return name;
    }

    @Override
    public void lock() {
        workLock.lock();
    }

    @Override
    public void lockInterruptibly() throws InterruptedException {
        workLock.lockInterruptibly();
    }

    @Override
    public boolean tryLock() {
        return workLock.tryLock();
    }

    @Override
    public boolean tryLock(long time, TimeUnit unit) throws InterruptedException {
        return workLock.tryLock(time, unit);
    }

    @Override
    public void unlock() {
        workLock.unlock();
    }

    @Override
    public Condition newCondition() {
        return workLock.newCondition();
    }


}
